package org.ilead.iserve.service.manager;

import org.ilead.iserve.model.HomePage;
import org.ilead.iserve.service.IHomePageService;

public class HomePageManager{
	private static HomePageManager instance = new HomePageManager();

	private IHomePageService homePageService;
	
	public static HomePageManager getInstance(){
		return instance;
	}
	
	public void setHomePageService(IHomePageService homePageService) {
		this.homePageService = homePageService;
	}

	public HomePage getHomePageByUserId(int userId){
		return homePageService.findByUserId(userId);
	}
	
	public HomePage getHomePageByUrl(String url){
		return homePageService.findByUrl(url);
	}
	
	public void saveHomePage(int userId, String url, String signature){
		HomePage page = getHomePageByUserId(userId);
		if(page == null){
			page = new HomePage();
			page.setUserId(userId);
			page.setUrl(url);
		}else{
			page.setSignature(signature);
		}
		homePageService.save(page);
	}
}
